//
//  MouoSinaMenuItemCell.m
//  WJSinaHomeMenu
//
//  Created by tqh on 2019/5/16.
//  Copyright © 2019 tqh. All rights reserved.
//

#import "MouoSinaMenuItemCell.h"


@interface MouoSinaMenuItemCell()

@property (nonatomic,strong) UILabel *label;
@property (nonatomic,strong) UIButton *deleteButton;

@end

@implementation MouoSinaMenuItemCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.label];
        [self.contentView addSubview:self.deleteButton];
    }
    return self;
}

- (void)layoutSubviews {
    self.label.frame = CGRectMake(0, 10, self.width - 10, self.height - 10);
    self.deleteButton.frame = CGRectMake(self.width - 20, 0, 20, 20);
}

#pragma mark - setter

-(void)setTitle:(NSString *)title {
    _title = title;
    self.label.text = title;
}

-(void)setIsMoving:(BOOL)isMoving
{
    _isMoving = isMoving;
    if (_isMoving) {
        self.label.hidden = YES;
    }else{
        self.label.hidden = NO;
    }
}

- (void)setIsEdit:(BOOL)isEdit {
    _isEdit = isEdit;
    if (isEdit) {
        self.deleteButton.hidden = NO;
        self.deleteButton.hidden = NO;
    }else {
        self.deleteButton.hidden = YES;
        self.deleteButton.hidden = YES;
    }
}

- (void)setIsPageIndex:(BOOL)isPageIndex {
    _isPageIndex = isPageIndex;
    if (isPageIndex) {
        self.label.backgroundColor = [UIColor colorWithHexString:@"#F6FBFF"];
        self.label.textColor = [UIColor colorWithHexString:@"#2296F3"];
    }else {
        self.label.backgroundColor = [UIColor colorWithHexString:@"F7F7F7"];
        self.label.textColor = [UIColor colorWithHexString:@"#666666"];
    }
}

#pragma mark - 事件监听

- (void)deleteButtonPressed {
    if (self.delegate && [self.delegate respondsToSelector:@selector(mouoSinaMenuItemCellDidCell:)]) {
        [self.delegate mouoSinaMenuItemCellDidCell:self];
    }
}

#pragma mark - 懒加载

- (UILabel *)label {
    if (!_label) {
        _label = [UILabel new];
        _label.backgroundColor = [UIColor colorWithHexString:@"F7F7F7"];
        _label.textColor = [UIColor colorWithHexString:@"#666666"];
        _label.font = [MouoFont PingFangSC_RegularWithSize:14];
        _label.textAlignment = NSTextAlignmentCenter;
    }
    return _label;
}

- (UIButton *)deleteButton {
    if (!_deleteButton) {
        _deleteButton = [UIButton new];
        [_deleteButton setImage:[UIImage imageNamed:@"mouo_sina_menu_delete"] forState:UIControlStateNormal];
//        _deleteButton.backgroundColor = [UIColor redColor];
        [_deleteButton addTarget:self action:@selector(deleteButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteButton;
}

@end
